
import {
    userSession
} from 'js/core/userSession';

const routes = [
    {
        path: '/login',
        getComponent: (nextState, cb) => {
            require.ensure([], (require) => {
                cb(null, require('views/login/login'))
            }, 'login')
        },
    },
    {
        path: '/',
        onEnter: (nextState, replace) => {
            if (!userSession.get() || !userSession.get().USERKEY) {
                replace({ pathname: '/login' });
            }
        },
        getComponent: (nextState, cb) => {
            require.ensure([], (require) => {
                cb(null, require('views/index/init'))
            }, 'init')
        },
        childRoutes: [
            {
                path: '/shopList',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/shopList/shopList'))
                    }, 'shopList')
                }
            },
            {
                path: '/floors(/:shopId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/floors/floors'))
                    }, 'floors')
                }
            },
            {
                path: '/flowSummary(/:shopId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/flowSummary/flowSummary'))
                    }, 'flowSummary')
                }
            },
            {
                path: '/floorsflowSummary(/:shopId/:areaId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/flowSummary/floorsflowSummary'))
                    }, 'floorsflowSummary')
                }
            },
            {
                path: '/brandsflowSummary(/:shopId/:areaId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/flowSummary/brandsflowSummary'))
                    }, 'brandsflowSummary')
                }
            },
            {
                path: '/retailPatternflowSummary(/:shopId/:areaId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/flowSummary/retailPatternflowSummary'))
                    }, 'retailPatternflowSummary')
                }
            },
            {
                path: '/retailPatterns(/:shopId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/retailPatterns/retailPatterns'))
                    }, 'retailPatterns')
                }
            },
            {
                path: '/brand(/:shopId)',
                getComponent: (nextState, cb) => {
                    require.ensure([], (require) => {
                        cb(null, require('views/brand/brand'))
                    }, 'brand')
                }
            },
        ]
    }
];

export { routes };